<template>
  <div class="home" style="height: 100%">
    <el-container style="height: 100%;">
      <el-aside :width="sideWidth+'px'">
        <Aside :is-collapse="isCollapse" />
      </el-aside>

      <el-container>
        <el-header style="border-bottom:1px solid #ccc;">
          <Header :collapse-btn-class="collapseBtnClass" :collapse="collapse" :user="user"/>
        </el-header>
        <el-main>
          <router-view @refreshUser="getUser"/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<style>
.el-header {
  background-color: #fff;
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}
</style>

<script>
// @ is an alias to /src
import Aside from "@/components/Aside";
import Header from "@/components/Header";

export default {
  data() {
    return {
      collapseBtnClass: "el-icon-s-fold",
      isCollapse: false,
      sideWidth: 200,
      user: {}
    }
  },
  components: {
    Aside,
    Header
  },
  created() {
    this.getUser()
  },
  methods: {
    getUser(){
      let username =localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")).username : {}
      //获取更新用户的数据
      axios.get("/user/username/" + username).then(res => {
        this.user = res.data
      })
    },
    collapse() {
      this.isCollapse = !this.isCollapse
      this.collapseBtnClass = this.collapseBtnClass == "el-icon-s-fold" ? "el-icon-s-unfold" : "el-icon-s-fold"
      if (this.isCollapse) {
        this.sideWidth = 50
        this.collapseBtnClass = 'el-icon-s-unfold'
      } else {
        this.sideWidth = 200
        this.collapseBtnClass = 'el-icon-s-fold'
      }
    },
  }
}
</script>

